package com.winit.schedule.job.tracker.conf;

import java.util.Properties;

import com.winit.schedule.core.conf.Configuration;

public class JobConfiguration extends com.winit.schedule.core.conf.JobConfiguration {

    public static final String  CONFIG_FILE                         = "uchedule.config.file";

    public static final String  DEFAULT_CONFIG_FILENAME             = "application.properties";

    /**
     * Job Tracker监听 端口号
     */
    public static final String  LISTEN_PORT                         = USCHEDULE_PREFIX + "listen.port";

    public static final int     DEFAULT_LISTEN_PORT                 = 8019;

    /**
     * 管理员密码
     */
    public static final String  ADMIN_PWD                           = USCHEDULE_PREFIX + "admin.password";

    public static final String  DEFAULT_ADMIN_PWD                   = "admin";

    /**
     * tasktracker是否断连检测周期（必须小于一个心跳超时时间）,最好是可以整除心跳超时时间
     */
    public static final String  HEARTBEAT_CHECK_INTERVAL_MS         = HEARTBEAT_PREFIX + "check.interval.ms";

    public static final long    DEFAULT_HEARTBEAT_CHECK_INTERVAL_MS = 300000;

    public static final String  DB_TYPE                             = "db.type";

    /**
     * mongodb 配置
     */
    public static final String  MONGODB_PREFIX                      = USCHEDULE_PREFIX + "mongodb.";

    public static final String  MONGODB_ADDRESS                     = MONGODB_PREFIX + "address";

    public static final String  MONGODB_DB                          = MONGODB_PREFIX + "db";

    public static final String  MONGODB_USERNAME                    = MONGODB_PREFIX + "username";

    public static final String  MONGODB_PASSWORD                    = MONGODB_PREFIX + "password";

    // mail config

    public static final String  MAIL_PREFIX                         = "mail.";

    /**
     * 是否开启邮件功能
     */
    public static final String  MAIL_ENABLE                         = MAIL_PREFIX + "enable";

    public static final String  MAIL_HOST                           = MAIL_PREFIX + "server.host";

    public static final String  MAIL_PORT                           = MAIL_PREFIX + "server.port";

    public static final String  MAIL_USERNAME                       = MAIL_PREFIX + "server.username";

    public static final String  MAIL_PASSWORD                       = MAIL_PREFIX + "server.password";

    public static final String  MAIL_TRANSPORT_PROTOCOL             = MAIL_PREFIX + "transport.protocol";
    public static final String  MAIL_SMTP_AUTH                      = MAIL_PREFIX + "smtp.auth";
    public static final String  MAIL_SMTP_STARTTLS_ENABLE           = MAIL_PREFIX + "smtp.starttls.enable";
    public static final String  MAIL_SMTP_TIMEOUT                   = MAIL_PREFIX + "smtp.timeout";
    public static final String  MAIL_DEBUG                          = MAIL_PREFIX + "debug";

    public static final String  ALARM_MAIL_FROM                     = "alarm.mail.from";

    public static final String  ALARM_MAIL_TO                       = "alarm.mail.to";

    /*
     * 日志保留时长（单位：天）
     */
    public static final String  LOG_RETAIN_DAYS                     = "log.retain.days";

    public static final int     DEFAULT_LOG_RETAIN_DAYS             = 30;

    /**
     * zookeeper注册地址检测，默认5分钟检查一次，用于激活zookeeper连接
     */
    public static final String  ZK_HEALTH_CHECK_ENABLE              = USCHEDULE_PREFIX + "zk.check.enable";

    public static final boolean DEFAULT_ZK_HEALTH_CHECK_ENABLE      = false;

    /**
     * 是否生产环境
     */
    public static final String  DEVELOP_MODE                        = USCHEDULE_PREFIX + "develop.mode";

    public static final boolean DEFAULT_DEVELOP_MODE                = false;

    /**
     * 白名单缓存自动刷新周期
     */
    public static final String  WHITELIST_CACHE_REFRESH_INVERVAL    = USCHEDULE_PREFIX + "whitelist.cache.refresh.inverval.s";

    public static final long DEFAULT_WHITELIST_CACHE_REFRESH_INVERVAL                = 300;

    /**
     * 定时任务判定异常任务可恢复时间
     */
    public static final String  RECOVERY_TIMEOUT_MS    = USCHEDULE_PREFIX + "recovery.timeout.s";

    public static final long DEFAULT_RECOVERY_TIMEOUT_MS               = 180000;

    /**
     * 短信告警KEY前缀
     */
    public static final String  ALERT_SMS_PREFIX = USCHEDULE_PREFIX + "alert.sms.";

    /**
     * 短信告警接收人
     */
    public static final String  ALERT_SMS_TO = ALERT_SMS_PREFIX + "to";

    /**
     * 短信告警周期
     */
    public static final String  ALERT_SMS_INVERVAL_MIN = ALERT_SMS_PREFIX + "interval.min";

    public static final int  DEFAULT_ALERT_SMS_INVERVAL_MIN = 10;

    /**
     * 禅道登录地址
     */
    public static final String ZENTAO_LOGIN_URI = USCHEDULE_PREFIX + "zentao.login.uri";

    public static final String DEFAULT_ZENTAO_LOGINURI = "http://zentao.winit.com.cn/index.php?m=user&f=login&t=json";


    public JobConfiguration(){
        String configFile = System.getProperty(JobConfiguration.CONFIG_FILE, JobConfiguration.DEFAULT_CONFIG_FILENAME);
        Configuration.addClassPathResource(configFile);
        Configuration.addClassPathResource("environment.properties");
        Configuration.addClassPathResource("password.properties");
    }

    public JobConfiguration(Properties props){
        this.setProps(props);
    }

}
